<template>
	<view class="beijingse mainpadding" v-if="pageShow">
		<!-- 1=待支付,2=待发货,3=待收货,4=待评论,5=售后订单(已弃用),6=已完成,7=已取消,8=取消审核中 -->
		<view class="bigtext fonweight" v-if="dataAll.state==1">等待买家付款</view>
		<view class="bigtext fonweight" v-if="dataAll.state==2">等待商家发货</view>
		<view class="bigtext fonweight" v-if="dataAll.state==3">等待买家收货</view>
		<view class="bigtext fonweight" v-if="dataAll.state==4">待评价</view>
		<view class="bigtext fonweight" v-if="dataAll.state==6">已完成</view>
		<view class="bigtext fonweight" v-if="dataAll.state==7">订单已取消</view>
		<view class="strongtext nofonweight margin_top1" v-if="dataAll.state==1">等待用户及时付款~</view>
		<view class="strongtext nofonweight margin_top1" v-if="dataAll.state==2">待商家发货~</view>
		<view class="strongtext nofonweight margin_top2" v-if="dataAll.state==3">物流配送中，请耐心等待</view>
		<view class="strongtext nofonweight margin_top2" v-if="dataAll.state==4">待评价</view>
		<view class="strongtext nofonweight margin_top2" v-if="dataAll.state==6">订单已完成</view>
		<view class="strongtext nofonweight margin_top2" v-if="dataAll.state==7">用户已取消订单</view>
		<view class="radius mainpadding ffffff margin_top" v-if="dataAll.address">
			<view class="flexleft">
				<view class="titletext fonweight margin_right3">{{dataAll.address.name}}</view>
				<view class="titletext fonweight"> {{dataAll.address.mobile}}</view>
			</view>
			<view class="titletext xiaohui margin_top2">{{dataAll.address.address}}</view>
		</view>
		<template v-if="dataAll.express_no">
			<view class="ffffff radius mainpadding ffffff margin_top2">
				<view class="flexbetween">
					<view class="sanshier xiaohei fonweight">{{dataAll.express_name}}</view>
					<view class="xiaohuang strongtext" @click="copy(dataAll.express_no)">点击复制</view>
				</view>
				<view class="ershiba xiaohei margin_top2">{{dataAll.express_no}}</view>
			</view>
		</template>
		<view class="ffffff radius margin_top mainpadding">
			<view class="ershiba zhonghei fonweight">订单商品</view>
			<view class="" v-for="item in dataAll.goods" :key="item.id">
				<view class="flexbetween margin_top" @click="jumpdetail('/pages_homepage/shangpinxq?id=',item.goods_id)">
					<image class="sptp" :src="item.image_text" mode=""></image>
					<view class="" style="width: 73%;">
						<view class="titletext xiaohei yhxk">{{item.title}}</view>
						<view class="strongtext xiaohei margin_top2 yhxk">{{item.difference}}</view>
						<view class="flexbetween margin_top2">
							<view class="titletext xiaocheng">{{item.price}}</view>
							<view class="ershil xiaocheng">x{{item.number}}</view>
						</view>
					</view>
				</view>
			</view>
			
		</view>
		<view class="ffffff radius mainpadding margin_top">
			<view class="flexbetween">
				<view class="ershil zhonghei">商品金额</view>
				<view class="ershil xiaocheng">{{dataAll.total_goods_price}}</view>
			</view>
			<!-- <view class="flexbetween margin_top">
				<view class="ershil zhonghei">运费</view>
				<view class="ershil xiaocheng">¥{{dataAll.freight_price}}</view>
			</view> -->
			<view class="flexbetween margin_top">
				<view class="ershil zhonghei">订单编号</view>
				<view class="ershil xiaohui">{{dataAll.order_no}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="ershil zhonghei">下单时间</view>
				<view class="ershil xiaohui">{{dataAll.createtime_text}}</view>
			</view>
			<view class="flexbetween margin_top" v-if="dataAll.username">
				<view class="ershil zhonghei">姓名</view>
				<view class="ershil xiaohui">{{dataAll.username}}</view>
			</view>
			<view class="flexbetween margin_top" v-if="dataAll.mobile">
				<view class="ershil zhonghei">电话</view>
				<view class="ershil xiaohui">{{dataAll.mobile}}</view>
			</view>
			<view class="flexbetween margin_top" v-if="dataAll.state!=1 && dataAll.state!=7">
				<view class="ershil zhonghei">支付方式</view>
				<view class="ershil xiaohui">{{dataAll.pay_type_text}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="ershil zhonghei">备注</view>
				<view class="ershil xiaohui">{{dataAll.remarks}}</view>
			</view>
		</view>
		<!-- 1=待支付,2=待发货,3=待收货,4=待评论,5=售后订单(已弃用),6=已完成,7=已取消,8=取消审核中 -->
		<!-- <view class="gudingdb ffffff mainpadding flexright" v-if="dataAll.state==6 || dataAll.state==7  || dataAll.state==4 || dataAll.state==1 || dataAll.state==3 || dataAll.state==2">
			<view class="qxbtn flexcenter margin_left3" v-if="dataAll.state==1 || dataAll.state==2" @click="currentid=dataAll.id;showModal('是否确认取消订单？')">取消订单</view>
			<view class="xhbtn flexcenter margin_left3" v-if="dataAll.state==1" @click="payment(dataAll)">立即支付</view>
			<view class="xhbtn flexcenter margin_left3" v-if="dataAll.state==3" @click="currentid=dataAll.id;showModal('是否确认收货？')">确认收货</view>
			<view class="xhbtn flexcenter margin_left3" v-if="dataAll.state==4" @click="pingjia(dataAll.id)">立即评价</view>
			<view class="qxbtn flexcenter margin_left3" v-if="dataAll.state==6 || dataAll.state==7 " @click="currentid=dataAll.id;showModal('是否确认删除当前订单？')">删除订单</view>
		</view> -->
		<moDal :message="modal" @modalSure="modalSure" @modalcancel="modalcancel"></moDal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				listid: "",
				dataAll: {},
				httpRequest,
				pageShow: false,
				modal:{
					modalShow:false,
					title:"",
				},
				currentid:"",
			}
		},
		onLoad(options) {
			this.listid = options.id
			
		},
		onShow() {
			this.getDetail()
		},
		methods: {
			pingjia(id){
				uni.navigateTo({
					url:"/pages_mypage/lijipj?id="+id
				})
			},
			getDetail() {
				httpRequest.request('/api/order/getOrderInfo', 'GET', {
					id: this.listid
				}, false, false, true).then(res => {
					this.dataAll = res.data
					this.pageShow = true
				})
			},
			showModal(val){
				this.modal.title = val
				this.modal.modalShow = true
			},
			modalSure(){
				if(this.modal.title=="是否确认取消订单？"){
					this.cancelorder(this.currentid)
				}else if(this.modal.title=="是否确认删除当前订单？"){
					this.deleteorder(this.currentid)
				}else if(this.modal.title=="是否确认收货？"){
					this.shouhuo(this.currentid)
				}
				this.modalcancel()
			},
			modalcancel(){
				this.modal.modalShow = false
			},
			payment(item) {
				let data = {
					pay_price: item.pay_price,
					type: item.order_type, //1=大礼包,2=普通商品,3=积分商品
					order_id: item.id,
					freight_price:item.freight_price
				}
				uni.navigateTo({
					url: "/pages_homepage/zhifu?msg=" + encodeURIComponent(JSON.stringify(data))
				})
			},
			cancelorder(id) {
				httpRequest.request('/api/order/cancelOrder', 'POST', {
					order_id: id,
				}).then(res => {
					httpRequest.toast(res.msg)
					this.getDetail()
				})
			},
			shouhuo(id){
				httpRequest.request('/api/order/confirmOrder', 'POST', {
					id: id,
				}).then(res => {
					httpRequest.toast(res.msg)
					this.getDetail()
				})
			},
			deleteorder(id){
				httpRequest.request('/api/order/delOrder', 'POST', {
					id: id,
				}).then(res => {
					httpRequest.toast(res.msg)
					setTimeout(()=>{
						uni.navigateBack(1)
					},1000)
				})
			},
			// 跳转申请退款
			tzsqtk(pid,id){
				uni.navigateTo({
					url:'/pages_mypage/shenqtuik?order_id='+pid+"&order_goods_id="+id
				})
			},
			tuikuanxq(id){
				uni.navigateTo({
					url:"/pages_mypage/tuihuoxq?id="+id
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.xhbtn {
		width: 170rpx;
		height: 67rpx;
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #FF9341;
		border-radius: 120rpx;
		border: 2rpx solid #FF9341;
	}
	.qxbtn {
		width: 170rpx;
		height: 67rpx;
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #666666;
		border-radius: 120rpx;
		border: 2rpx solid #666666;
	}
	.sptp {
		width: 150rpx;
		height: 150rpx;
		min-width: 150rpx;
		border-radius: 14rpx 14rpx 14rpx 14rpx;
	}
</style>
